<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .box {
        width: 100px;
        height: 100px;
        background-color: cyan;
        position: absolute;
        left: 0px;
      }
    </style>
  </head>
  <body>
    <div class="box"></div>

    <script>
      var boxEle = document.querySelector(".box");
      boxEle.onclick = function () {
        var num = 0;
        var timer = setInterval(function () {
          //   num += 100;
          //   console.log(111);
          //   console.log(num);
          boxEle.style.left = ++num + "px";

          if (boxEle.offsetLeft >= window.innerWidth - boxEle.offsetWidth) {
            //到达浏览器边界的时候停止运动
            clearInterval(timer);
          }
        }, 1);
      };
    </script>
  </body>
</html>
